package com.subway.babynote;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.subway.babynote.syncdata.ClientDataRecord.contactRecord;
import com.subway.babynote.syncdata.ClientDataRecordBase;
import com.subway.babynote.syncdata.StringUtil;
import com.subway.babynote.syncservice.syncapi;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
/*水*/
public class aboutus extends Activity {
	private static final int INVISIBLE = 0x00000004;
	Intent In;
	ListView lv;
	NotedbHelper notedb;
	Cursor cur;
	int col;
	String[] from;
	int[] to;
	Button login_button;
	private LinearLayout linearLayout, statistics, sync, more;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.aboutus);
		setTitle(R.string.aboutustitle);
		In= new Intent();
	//	initTabFunction();
		login_button = (Button) findViewById(R.id.login_button);
		lv = (ListView)findViewById(R.id.contact_list);
		lv.setFocusable(false);
		try {
			notedb = new NotedbHelper(this);
			if (syncapi.getSyncImpl().getUserid() != -1) {
				login_button.setVisibility(INVISIBLE);
				login_button.setClickable(false);
			}
		/*	cur= notedb.getOurContact();
			syncapi.getSyncImpl().informSync(
					syncapi.operation_type.getcontact.code,
					notedb.nowTime());
					*/
			List<contactRecord> lc=syncapi.getSyncImpl().getOurContact();
			ArrayList<HashMap<String, Object>> contacts = new ArrayList<HashMap<String, Object>>();
		/*	while (!cur.isAfterLast()) {
				HashMap<String, Object> contact = new HashMap<String, Object>();
				feed.put("time", StringUtil.sql_date2str(StringUtil
						.int2date(cur.getInt(1))).substring(10,16));
				feed.put("name", cur.getString(2));
				feed.put("quantity", cur.getFloat(3));
				feed.put("unit", cur.getString(4));
				
				contacts.add(contact);
				cur.moveToNext();
			}*/
			
			Iterator<contactRecord> it = lc.iterator();
			while(it.hasNext()){
				HashMap<String, Object> contact = new HashMap<String, Object>();
				contact.put("name", it.next().name);
				contact.put("value", it.next().value);
				contacts.add(contact);
			}
			from = new String[] { "name", "value" };
			to = new int[] { R.id.item1, R.id.item2, };
			ListAdapter listAdapter = new SimpleAdapter(this, contacts, R.layout.contact_item,from, to);	
			// listAdapter = new SimpleCursorAdapter(this, R.layout.contact_item, 
			//		cur,from, to);		
			//this.startManagingCursor(cur);

			lv.setAdapter(listAdapter);
			}catch(Exception e){
				 Log.v("aboutus", " e=" + e.getMessage());
			}
			
			login_button.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					In.setClass(aboutus.this, login.class);
					startActivity(In);
				}
			});
	}
	
	
	
	public void onDestroy(){
    	notedb.close();
	   super.onDestroy();
	   
	}
}